FILES := etc/init.d/rip-sender etc/rip-sender.conf.dist usr/sbin/rip-sender
TARGET := rip-sender
RFILES := $(addprefix deb/$(TARGET)/,$(FILES))
VERSION := 0.3.r$(shell ./get_revision.sh $(FILES))

all: $(TARGET).$(VERSION).deb

$(TARGET).$(VERSION).deb: deb/$(TARGET)/DEBIAN/md5sums deb/$(TARGET)/DEBIAN/control deb/$(TARGET)/DEBIAN/postinst
	dpkg-deb --build deb/$(TARGET) $@

deb/$(TARGET)/DEBIAN/md5sums: $(RFILES)
	mkdir -p $(dir $@)
	cd deb/$(TARGET) && md5sum $(FILES) > DEBIAN/md5sums

deb/$(TARGET)/DEBIAN/control:
	mkdir -p $(dir $@)
	./create_control.sh $(VERSION) $(TARGET) $(FILES) > $@

deb/$(TARGET)/DEBIAN/postinst:
	mkdir -p $(dir $@)
	./create_postinst.sh $(TARGET) > $@
	chmod +x $@

$(RFILES):
	mkdir -p $(dir $@)
	cp "$(patsubst deb/$(TARGET)/%,%,$@)" "$@"

clean:
	rm -r deb/

release: $(TARGET).$(VERSION).deb
	svn add $(TARGET).$(VERSION).deb
	scp $(TARGET).$(VERSION).deb pauc@urbanovich.net:/var/www/urbanovich.net/public/
	./create_wiki.sh $(TARGET).$(VERSION).deb > ../wiki/QuickStart.wiki
	svn ci -m "Build $(TARGET).$(VERSION).deb" $(TARGET).$(VERSION).deb ../wiki/QuickStart.wiki
